package com.ltkj.shop.controller;

import com.ltkj.common.core.utils.poi.ExcelUtil;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.web.page.TableDataInfo;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.annotation.RequiresPermissions;
import com.ltkj.shop.domain.ShopRestMenuType;
import com.ltkj.shop.service.IShopRestMenuTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 餐饮菜品类型Controller
 * 
 * @author xupf
 * @date 2023-10-07
 */
@Api(tags = "餐饮菜品类型")
@RestController
@RequestMapping("/menuType")
public class ShopRestMenuTypeController extends BaseController
{
    @Autowired
    private IShopRestMenuTypeService shopRestMenuTypeService;

    /**
     * 查询餐饮菜品类型列表
     */
    @ApiOperation("查询餐饮菜品类型列表")
    @RequiresPermissions("shop:menuType:list")
    @GetMapping("/list")
    public TableDataInfo list(ShopRestMenuType shopRestMenuType)
    {
        if (null == shopRestMenuType.getRestaurantId()) {
            return getDataTable(new ArrayList<>());
        }
        List<ShopRestMenuType> list = shopRestMenuTypeService.selectShopRestMenuTypeList(shopRestMenuType);
        return getDataTable(list);
    }

    /**
     * 导出餐饮菜品类型列表
     */
    @ApiOperation("导出餐饮菜品类型列表")
    @RequiresPermissions("shop:menuType:export")
    @Log(title = "餐饮菜品类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopRestMenuType shopRestMenuType)
    {
        List<ShopRestMenuType> list = shopRestMenuTypeService.selectShopRestMenuTypeList(shopRestMenuType);
        ExcelUtil<ShopRestMenuType> util = new ExcelUtil<ShopRestMenuType>(ShopRestMenuType.class);
        util.exportExcel(response, list, "餐饮菜品类型数据");
    }

    /**
     * 获取餐饮菜品类型详细信息
     */
    @ApiOperation("获取餐饮菜品类型详细信息")
    @RequiresPermissions("shop:menuType:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopRestMenuTypeService.selectShopRestMenuTypeById(id));
    }

    /**
     * 新增餐饮菜品类型
     */
    @ApiOperation("新增餐饮菜品类型")
    @RequiresPermissions("shop:menuType:add")
    @Log(title = "餐饮菜品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopRestMenuType shopRestMenuType)
    {
        return toAjax(shopRestMenuTypeService.insertShopRestMenuType(shopRestMenuType));
    }

    /**
     * 修改餐饮菜品类型
     */
    @ApiOperation("修改餐饮菜品类型")
    @RequiresPermissions("shop:menuType:edit")
    @Log(title = "餐饮菜品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopRestMenuType shopRestMenuType)
    {
        return toAjax(shopRestMenuTypeService.updateShopRestMenuType(shopRestMenuType));
    }

    /**
     * 删除餐饮菜品类型
     */
    @ApiOperation("删除餐饮菜品类型")
    @RequiresPermissions("shop:menuType:remove")
    @Log(title = "餐饮菜品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shopRestMenuTypeService.deleteShopRestMenuTypeByIds(ids));
    }
}
